/**
 * @Project : algorithm-learning
 * @Author : Ruoyu Wang
 * @User : Momenta
 * @DateTime : 2024/4/16 16:26
 */

#include <iostream>
#include <vector>

using namespace std;

class Solution {
public:
    int maxArea(vector<int> &height) {
        int res = 0;
        int l = 0, r = height.size() - 1;
        while (l < r) {
            res = max(res, (r - l) * min(height[l], height[r]));
            if (height[l] <= height[r]) {
                int tmp = height[l];
                l++;
                while (l < r && height[l] <= tmp) {
                    l++;
                }
            } else {
                int tmp = height[r];
                r--;
                while (l < r && height[r] <= tmp) {
                    r--;
                }
            }
        }
        return res;
    }
};